#ifndef SQLCONNPOOL_H
#define SQLCONNPOOL_H

#include <mysql/mysql.h>
#include <string.h>
#include <queue>
#include <mutex>
#include <semaphore.h>
#include <thread>

#include "../log/log.h"

class SqlConnPool {
public:
    static SqlConnPool* instance();

    MYSQL* getConn();
    void freeConn(MYSQL* conn);
    int getFreeConnCount();

    void init(const char* host, int port,
                const char* user, const char* pwd,
                const char* dbName, int connSize);
    void closePool();
private:
    SqlConnPool();
    ~SqlConnPool();

    int maxConnSize_;
    int curConnSize_;
    int freeConnSize_;

    std::queue<MYSQL*> connQue_;
    std::mutex mtx_;
    sem_t sem_;
};


#endif